package com.hqd.ch03.v12.reader.xml.doc.support;

import com.hqd.ch03.v12.io.Resource;
import com.hqd.ch03.v12.reader.xml.doc.support.AbstractDocumentLoader;
import org.dom4j.io.SAXReader;
import org.xml.sax.InputSource;

import java.io.StringReader;

/**
 * 基于dom4j的实现
 */
public class Dom4jDocumentLoader extends AbstractDocumentLoader {
    @Override
    protected InputSource getInputSource(Resource resource) throws Exception {
        SAXReader reader = new SAXReader();
        org.dom4j.Document doc = reader.read(resource.getInputStream());
        StringReader stringReader = new StringReader(doc.asXML());
        return new InputSource(stringReader);

    }
}
